/**
 * @title: SportteryChooseActivity
 * @package:com.esun.rabbit2.viewer.mainact.lotteryhallact
 * @description: 球类彩票购彩的抽象Activity
 * @author: liugan
 * @date:2012.03.13 上午10:28
 */
package com.esun.cheetah.view.personal.sportlotteryfootball;

import android.app.Activity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

/**
 * 
 * @Package com.esun.cheetah.view.personal.sportlotteryfootball.SportteryChooseActivity
 * @ClassName: SportteryChooseActivity
 * @Description: TODO(choose football lottery abstract activity)
 * @author handy <br/>
 * @date create at 2012-7-31 下午2:53:43
 *
 */
public abstract class SportteryChooseActivity extends Activity {

	/**
	 * @field: pageFlag
	 * @description: 标识当前Activity显示的界面（0表示选择比赛界面，1表示购彩界面，-1表示无需界面）
	 */

	@Override
	protected void onResume() {
		super.onResume();

		if (this.getActiveCount() < 2) {
			this.setCurrentPageFlag(0);
		}

		if (getPageFlag() == -1) {
			getParent().finish();
		} else if (getPageFlag() == 0) {
			setContentView(getChooseListPageView());
		} else if (getPageFlag() == 1) {
			setContentView(getBuyLotteryPageView());
		}
	}

	public abstract int getPageFlag();

	/**
	 * @title: getChooseListPageView
	 * @description: 获得选择比赛视图
	 * @return 比赛列表视图
	 */
	protected abstract View getChooseListPageView();

	/**
	 * @title: getBuyLotteryPageView
	 * @description: 获得购彩页面视图
	 * @return 购彩页面视图
	 */
	protected abstract View getBuyLotteryPageView();

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_MENU
				|| keyCode == KeyEvent.KEYCODE_DPAD_LEFT
				|| keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			Activity parent = getParent();
			if (parent != null) {
				parent.onKeyDown(keyCode, event);
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onTrackballEvent(MotionEvent event) {
		Activity parent = getParent();
		if (parent != null) {
			parent.onTrackballEvent(event);
			return true;
		}
		return false;
	}

	public int getCurrentPageFlag() {
		return getPageFlag();
	}

	public void setCurrentPageFlag(int i) {
		setPageFlag(i);
	}

	public abstract void setPageFlag(int i);

	@Override
	protected void onPause() {
		super.onPause();
	}

	public abstract int getActiveCount();

}
